<template>
<div>
  <el-dialog
    width="30%"
    :title="'修改个人信息'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="100px" size="mini" label-position="left">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="dataForm.name" placeholder="姓名"></el-input>
      </el-form-item>
      <el-form-item label="职位" prop="type">
        <el-input v-model="dataForm.type" placeholder="职位"></el-input>
      </el-form-item>
      <el-form-item label="入职时间" prop="entryDate">
        <el-date-picker
          v-model="dataForm.entryDate"
          type="date"
          placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="工作部门" prop="workcellId">
        <el-select v-model="dataForm.workcellId" placeholder="请选择">
          <el-option
            v-for="item in options"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="邮箱" prop="email">
        <el-input v-model="dataForm.email" placeholder="邮箱"></el-input>
      </el-form-item>
      <el-form-item label="头像" prop="avatarUrl">
        <single-upload @input="getAvatarUrl"></single-upload>
        <img width="50%" :src="dataForm.avatarUrl">
      </el-form-item>

    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
import SingleUpload from "../../../components/upload/singleUpload"
export default {
  name: "peoplemanagement-update",
  data() {
    return {
      codeOptions: [
        {
          value: 0,
          label: "A"
        },
        {
          value: 1,
          label: "B"
        }
      ],
      options: [
        {value:1,label:'JW01'},
        {value:2,label:'JW02'},
        {value:3,label:'JW03'},
        {value:4,label:'JW04'},
        {value:5,label:'JW05'},
      ],
      visible: false,
      dataForm: {
        id: '0',
        name:'',
        type:'',
        entryDate:'',
        workCell:'',
        email:'',
        avatarUrl:'',
        workcellId:0
      },
      dataRule: {
        name: [
          {required: true, message: '姓名不能为空', trigger: 'blur'}
        ],
        type: [
          {required: true, message: '职位不能为空', trigger: 'blur'}
        ],
        entryDate: [
          {required: true, message: '入职时间不能为空', trigger: 'blur'}
        ],
        workCell: [
          {required: true, message: '工作部门不能为空', trigger: 'blur'}
        ],
        email: [
          {required: true, message: '邮箱不能为空', trigger: 'blur'}
        ],
        avatarUrl:[
          {required: true, message: '头像不能为空', trigger: 'blur'}
        ],
        workcellId: [
          {required: true, message: '工作部门不能为空', trigger: 'blur'}
        ],
      }
    }
  },
  components:{
    SingleUpload
  },
  methods: {
    getAvatarUrl(url){
      this.dataForm.avatarUrl = url
    },
    removeDomain(item) {
      var index = this.dataForm.jigs.indexOf(item)
      if (index !== -1) {
        this.dataForm.jigs.splice(index, 1)
      }
    },
    addDomain() {
      this.dataForm.jigs.push({
        code: '',
        key: Date.now()
      });
    },
    handleChange(value) {
    },
    clearTopData() {
      this.dataForm.billNo = ''
      this.dataForm.submitId = ''
      this.dataForm.productionLineId = ''
    },
    init(id) {
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id) {
          this.$http({
            url: `http://localhost:10000/gongjiajumain/user/info/${this.dataForm.id}`,
            method: 'get',
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              console.log(data.user)
              this.dataForm = data.user
            }
          })
        }
      })
    },
    // 表单提交
    dataFormSubmit() {
      console.log(this.dataForm)
      this.$http.post("http://localhost:10000/gongjiajumain/user/update",this.dataForm)
      .then(res=>{
        console.log(res)
        this.$message({
          message: '不要怀疑,你已经修改成功啦~꒰ঌ( ⌯\' \'⌯)໒꒱',
          type: 'success'
        });
        this.visible = false
        this.$emit('refreshDataList')
      })

      // this.$refs['dataForm'].validate((valid) => {
      //   if (valid) {
      //     this.$http({
      //       url: this.$http.adornUrl(`/gongjiajumain/scrapsubmithistory/${!this.dataForm.id ? 'save' : 'update'}`),
      //       method: 'post',
      //       data: this.$http.adornData({
      //         'id': this.dataForm.id || undefined,
      //         'seqId': this.dataForm.seqId,
      //         'code': this.dataForm.code,
      //         'submitId': this.dataForm.submitId,
      //         'usedCount': this.dataForm.usedCount,
      //         'scrapReason': this.dataForm.scrapReason,
      //         'scrapPhotoUrl': this.dataForm.scrapPhotoUrl,
      //         'firstAcceptor': this.dataForm.firstAcceptor,
      //         'firstTime': this.dataForm.firstTime,
      //         'firstReason': this.dataForm.firstReason,
      //         'finalAcceptor': this.dataForm.finalAcceptor,
      //         'finalTime': this.dataForm.finalTime,
      //         'finalReason': this.dataForm.finalReason,
      //         'status': this.dataForm.status
      //       })
      //     }).then(({data}) => {
      //       if (data && data.code === 0) {
      //         this.$message({
      //           message: '操作成功',
      //           type: 'success',
      //           duration: 1500,
      //           onClose: () => {
      //             this.visible = false
      //             this.$emit('refreshDataList')
      //           }
      //         })
      //       } else {
      //         this.$message.error(data.msg)
      //       }
      //     })
      //   }
      // })
    }
  }
}
</script>

<style scoped lang="scss">

</style>
